﻿using System;
using Microsoft.VisualStudio.SharePoint;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;

namespace CodeCounsel.SharePoint.DevTools.ItemTypes
{
    [Export(typeof(ISharePointProjectItemTypeProvider))]
    [SharePointProjectItemType("CodeCounsel.SharePoint.DevTools.CustomAction")]
    public class CustomAction
        : ISharePointProjectItemTypeProvider
    {
        IServiceProvider _serviceProvider;

        public void InitializeType(ISharePointProjectItemTypeDefinition typeDefinition)
        {
            _serviceProvider = typeDefinition.ProjectService.ServiceProvider;
            typeDefinition.Name = "CustomAction";
            typeDefinition.SupportedDeploymentScopes =
                SupportedDeploymentScopes.Site | SupportedDeploymentScopes.Web;
            typeDefinition.SupportedTrustLevels = SupportedTrustLevels.All;

            typeDefinition.ProjectItemMenuItemsRequested +=
                delegate(object sender, SharePointProjectItemMenuItemsRequestedEventArgs e)
                {
                    IMenuItem item = e.ViewMenuItems.Add("Testje");
                    item.Click += new EventHandler<MenuItemEventArgs>(item_Click);
                };
        }

        void item_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem item = (ISharePointProjectItem)e.Owner;
            //VsShellUtilities.OpenDocumentWithSpecificEditor(
            //    _serviceProvider, 
            //    item.DefaultFile.FullPath, 
            //    new Guid("293F5E05-8E48-4D51-B1E3-7E8828D6F548"),
            //    VSConstants.LOGVIEWID_Primary);
        }
    }
}
